﻿"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer: 
"       V
"       http://weibo.com/unsuccessful
"
" Version: 
"       1.0 - 2013-02-16 21:31:44
"
" Sections:
"    -> Base
"       -> Encoding
"    -> General
"    -> Encoding
"    -> UI
"    -> User
"    -> Helper functions
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Base
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
" source $VIMRUNTIME/gvimrc_example.vim
source $VIMRUNTIME/vimrc_example.vim
" 这里面的 ctrl+y 跟 emmet 冲突，先不用
source $VIMRUNTIME/mswin.vim
behave mswin

" Enable filetype plugins
filetype on
filetype plugin on
filetype indent on

" syntax
syntax on
syntax enable " Enable syntax highlighting

" Alt组合键不隐射到菜单上,配置alt映射时这个很重要
set winaltkeys=no

"""""""""""""""""""""""""""""""
" => Encoding
"""""""""""""""""""""""""""""""
" 设置编码
set encoding=utf-8 " or 'enc' 
set fileencoding=utf-8 " or 'fenc'
set fileencodings=utf-8,gbk,ucs-bom,cp936,latin-1 " or 'fencs'

" Use Unix as the standard file type
set ffs=unix,dos,mac

"设置菜单语言
set langmenu=en_US.utf-8 

" 解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" 解决consle输出乱码
language messages en_US.utf-8


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set to auto read when a file is changed from the outside
set autoread

" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4

" user spaces instead of tabs
" 在输入 tab 后, vim 用恰当的空格来填充这个 tab
set expandtab      

set nocompatible " 设置不兼容

set number
" Make no *.bak
set nobackup
" keep backup while we are editing
set writebackup

" 启动的时候不显示那个援助索马里儿童的提示 
set shortmess=atI

" Custom Commands
command! DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
    \ | wincmd p | diffthis


"Fix findstr for Win32
if has("win32")
  set grepprg=findstr\ /R\ /S\ /N
  set gcr=n-v-c:block-blinkon0,i-ci:ver15-blinkon0,ve:ver15-blinkon0
endif

" do not highlight searches
" set nohlsearch

" taglist
let Tlist_Show_One_file=1                  " 不同时显示多个的tag，只显示当前文件的 
let Tlist_Exit_OnlyWindow=1                " 如果taglist窗口是最后一个窗口，则退出vim 
let Tlist_Sort_Type="name"                 " 默认按方法位置排序, 这里按名称排序

" do not highlight searches
set nohlsearch

" Make autoindent happen
set autoindent
" Show actual currsor position
set ruler 
set showcmd
" set showmatch
set showmode

" 解决中文折行问题
set nolbr

" 中文排版问题
" set nolbr
" Linebreak on 500 characters
" set lbr
" set tw=500

set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines

" 搜索时忽略大小写，但在有一个或以上大写字母时仍保持对大小写敏感 
set ignorecase smartcase

"set default foldmethod
" manual 手工定义折叠
" indent 更多的缩进表示更高级别的折叠
" expr   用表达式来定义折叠
" syntax 用语法高亮来定义折叠
" diff   对没有更改的文本进行折叠
" marker 对文中的标志折叠
set foldmethod=marker

" 防止出现文件夹没有创建文件权限的情况
set directory+=$VIM/temp
set backupdir+=$VIM/temp

"""""""""""""""""""""""""""""""
" => NERDTree
"""""""""""""""""""""""""""""""
let NERDChristmasTree=1
let NERDTreeAutoCenter=1
let NERDTreeBookmarksFile=$VIM.'\temp\NerdBookmarks.txt'
let NERDTreeShowBookmarks=1
let NERDTreeMouseMode=2
let NERDTreeShowFiles=1
" let NERDTreeShowHidden=1
" let NERDTreeShowLineNumbers=1
" let NERDTreeWinPos='left'
let NERDTreeWinSize=31

" command Dir NERDTreeToggle
map <C-k><C-b> :NERDTreeToggle<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => UI
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Themes setting
" let g:molokai_original = 1
" colorscheme molokai
" colorscheme zellner "mac class
" colorscheme peachpuff
" colorscheme chocolateliquor

" set background=light
set background=dark
colorscheme solarized

" 字体 && 字号
set guifont=Courier\ New:h10
" set guifont=Consolas:h10
" set guifont=Source_Code_Pro:h9:cANSI
" 设置中文字体
" set gfw=仿宋:h10:cGB2312

" Set extra options when running in GUI mode
if has("gui_running")
    set t_Co=256
    "au GUIEnter * simalt ~x  " 窗口启动时自动最大化
	" winpos 50 50			 " 设置出现位置
	" set lines=40 columns=160 " 设置高度跟宽度
	set lines=30 columns=120 " 设置高度跟宽度
    " set guioptions-=m       " 隐藏菜单栏
    set guioptions-=T         " 隐藏工具栏
    " set guioptions-=L       " 隐藏左侧滚动条
    " set guioptions-=r       " 隐藏右侧滚动条
    " set guioptions-=b       " 隐藏底部滚动条
    " set showtabline=0       " 隐藏Tab栏
    " set guitablabel=%M\ %t
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => User
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Google Go
" autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
let s:tlist_def_go_settings = 'go;f:func;v:var;t:type'

" autocmd BufNewFile,BufRead *.di setfiletype d
let tlist_d_settings='d;c:classes;d:macro definitions;e:enumerators'
nnoremap <silent> <F2> :TlistToggle<CR>

" let snips_author='小败'

" 高亮当前行
" set cursorline

" 高亮当前列
" set cursorcolum

"""""""""""""""""""""""""""""""
" => Emmet
"""""""""""""""""""""""""""""""
let g:user_emmet_settings = {
  \  'indentation' : '  ',
  \  'perl' : {
  \    'aliases' : {
  \      'req' : 'require '
  \    },
  \    'snippets' : {
  \      'use' : "use strict\nuse warnings\n\n",
  \      'warn' : "warn \"|\";",
  \    }
  \  }
  \}

let g:user_emmet_expandabbr_key = '<A-o>'
let g:use_emmet_complete_tag = 1
" let g:user_emmet_mode='n'    "only enable normal mode functions.
" let g:user_emmet_mode='inv'  "enable all functions, which is equal to
" let g:user_emmet_mode='a'    "enable all function in all mode.

"""""""""""""""""""""""""""""""
" => TabBar
"""""""""""""""""""""""""""""""
map <C-H> <C-W>h
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-L> <C-W>l

" 设置 TabBar 高度
" let g:Tb_MaxSize = 3
"
"默认情况下，只有用户新建了标签页才会在窗口上方显示标签栏，这是由选项
"set showtabline=1决定的。如果我们希望总是显示标签栏，那么可以用
"set showtabline=2命令来设置。如果我们希望完全不显示标签栏，
"那么可以使用set showtabline=0来设置。
" set showtabline=2

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 比较文件差别
" set diffexpr=MyDiff()
" function MyDiff()
"   let opt = '-a --binary '
"   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
"   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
"   let arg1 = v:fname_in
"   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
"   let arg2 = v:fname_new
"   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
"   let arg3 = v:fname_out
"   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
"   let eq = ''
"   if $VIMRUNTIME =~ ' '
"     if &sh =~ '\<cmd'
"       let cmd = '""' . $VIMRUNTIME . '\diff"'
"       let eq = '"'
"     else
"       let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
"     endif
"   else
"     let cmd = $VIMRUNTIME . '\diff'
"   endif
"   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
" endfunction

" 引号 && 括号自动匹配
" inoremap ( ()<left>
" inoremap [ []<left>
" inoremap { {}<left>
" :inoremap ) <c-r>=ClosePair(')')<CR>
" :inoremap } <c-r>=ClosePair('}')<CR>
" :inoremap ] <c-r>=ClosePair(']')<CR>
" function ClosePair(char)
" 	if getline('.')[col('.') - 1] == a:char
" 		return "\<right>"
" 	else
" 		return a:char
" 	endif
" endf

"""""""""""""""""""""""""""""""
" learn vimscript the hard way
"""""""""""""""""""""""""""""""

let mapleader = ','
" let maplocalleader = '\\'
" edit my vimrc file
:nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" source my vimrc file
:nnoremap <leader>sv :source $MYVIMRC<cr>
" surrond " to word
" :nnoremap <leader>" viw<esc>i"<esc>hbi"<esc>lel
" :nnoremap <leader>" ea"<esc>hbi"<esc>lel
nnoremap <leader>" bi"<esc>ea"<esc>
" selected word surrond \" 不完美，在尾部会有问题
" :vnoremap " <esc>i"<esc>`<i"<esc>vi"
" vnoremap " xi""<esc>hp


